$(function () {
    // $('#myTab').click(function () {
    //     var url = $('#application_url').val();
    //     window.location.href = url;
    // })

    $('#fwspA').click(function () {
        var url = $('#access_application_url').val();
        window.location.href = url + "?shenPiGroup=5";
    })

    //搜索
    $(".search").focus(function () {
        $(this).css({
            "border": "1px solid #2194f1"
        })
    })

    $(".search").blur(function () {
        $(this).css({
            "border": "1px solid #e2e2e2"
        })
    })


    $('form[name="search_audit"]').find('.search').keydown(function (event) {
        if (event.keyCode == 13) {
            $('#my_application_state').val(0);
            $('#my_application_result').val(0);
            var search = $('form[name="search_audit"]').find('.search').val(),
                ajaxPageUrl = $('#my_application_page_url').val(),
                param = $('form[name="search_audit"]').serialize(),
//          pageSize = parseInt($('#list .number').text(), 10);
                pageSize = 10;
            ajaxPageUrl += '?pageSize=' + pageSize + '&index=0';

            get_list(param, ajaxPageUrl);
            return false;
        }
    });

    $('form[name="search_audit"]').on('click', '#subForm', function () {
        $('#my_application_state').val(0);
        $('#my_application_result').val(0);
        var search = $('form[name="search_audit"]').find('.search').val(),
            ajaxPageUrl = $('#my_application_page_url').val(),
            param = $('form[name="search_audit"]').serialize(),
//          pageSize = parseInt($('#list .number').text(), 10);
            pageSize = 10;
        ajaxPageUrl += '?pageSize=' + pageSize + '&index=0';

        get_list(param, ajaxPageUrl);
    })

    //选择页面
    $("body").delegate("#page_list .pagination a", "click", function (e) {
        e.preventDefault();
        var cs = $(this).attr('href').split('?'),
            ajaxPageUrl = $('#my_application_page_url').val(),
//          pageSize = parseInt($('#list .number').text(), 10),
            pageSize = 10,
            workflow_status = $('#my_application_state').val(),
            result = $('#my_application_result').val(),
            search = $('form[name="search_audit"]').find('.search').val(),
            param = {};

        param.pageSize = pageSize;
        param.workflow_status = workflow_status;
        param.result = result;
        param.search = search;
        ajaxPageUrl = ajaxPageUrl + '?' + cs[1];

        get_list(param, ajaxPageUrl);
    });
})

/**
 * 设置状态
 * @param state 类型，1审批结果、2审批进程
 * @param value 状态值
 * @parma index 下标
 */
function setStatus(resultValue, statusValue, index) {
    var ajaxPageUrl = $('#my_application_page_url').val(),
//      pageSize = parseInt($('#list .number').text(), 10),
        pageSize = 10,
        search = $('form[name="search_audit"]').find('.search').val(),
        param = {};

    param.pageSize = pageSize;
    param.workflow_status = statusValue;
    param.result = resultValue;
    param.search = search;
    param.index = index;

    get_list(param, ajaxPageUrl);
}


function get_list(param, url) {
    $.ajax({
        type: "GET",
        url: url,
        data: param,
        datatype: "json",
        //成功返回之后调用的函数
        success: function (data) {
            if (data.code == 200) {
                layer.msg('加载成功');
                $('.myBagListBox').html(data.data.res.str2);
                var ajax = data.data.res.ajax;
                $('#current_page').val(ajax.page);
                $('#my_application_state').val(ajax.workflow_status);
                $('#my_application_result').val(ajax.result);
            }
        },
        //调用出错执行的函数
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            layer.msg('系统错误');
        }
    });
}